using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace IQIGame.Onigao.Framework
{
    public class ExRectMask2D : RectMask2D, IUGUIEx
    {
        public float weakFactor { get; set; } = 0f;

        public object dynamicData { get; set; }

        public void SetActive(bool active)
        {
            gameObject.SetActive(active);
        }

        public override void UpdateClipSoftness()
        {
            base.UpdateClipSoftness();
            if (_weakSoftnessMaskTargets == null) return;
            foreach (var graphic in _weakSoftnessMaskTargets)
            {
                graphic.SetClipSoftness((Vector2)softness * weakFactor);
            }
        }

        public void AddWeakSoftnessMaskTarget(MaskableGraphic target)
        {
            _weakSoftnessMaskTargets ??= new HashSet<MaskableGraphic>();
            _weakSoftnessMaskTargets.Add(target);
        }

        public void RemoveWeakSoftnessMaskTarget(MaskableGraphic target)
        {
            _weakSoftnessMaskTargets?.Remove(target);
        }

        private HashSet<MaskableGraphic> _weakSoftnessMaskTargets;
    }
}